<?
//Text 0.0.3
class sym_text extends symbiont{
    public function ___main($design, $id=0){
        global $kernel;
        $kernel->library_add('paragraph');
        
        $design=$this->_check($design);
        $d=new design($design, 'text', false);
        
        $p=new paragraph($id);
        $p->read();
        $this->content=$p->content;
        
        $d->inc();
    }
    public function ___admin($design, $id=0, $symbiont=''){
        global $sql, $kernel;
        
        $kernel->library_add('paragraph');
        
        $design=$this->_check($design, 'admin');
        $d=new design($design, 'text', false);
        
        $this->content='';
        $this->id=$id;
        $this->symbiont=$symbiont;
        
        $this->infos='';
        $this->languages='';
        $languages=$sql->select_each('languages', 'abbr', array('is_enabled'=>1), '', 'position');
        $p=new paragraph($id);
        foreach($languages as $val){
            $this->abbr=$val['abbr'];
            $p->read($val['id']);
            $this->content=$p->content;
            $this->languages.=design::run($this->language);
            $this->infos.=design::run($this->info);
        }
        
        $d->inc();
    }
    public function ___db_save($design){
        global $sql, $user, $kernel;
        if($user->access_level<9||!isset($_POST['content'])||!isset($_POST['id'])) return;
        $kernel->library_add('paragraph');
        $id=data::number($_POST['id']);
        $p=new paragraph($id);
        foreach($_POST['content'] as $key=>$val){
            $abbr=data::word($key);
            $content=data::safe($val);
            $lng_id=$sql->select_each('languages', 'id', array('abbr'=>$abbr), '', '', 1);
            if($content){
                $p->set($lng_id, '', $content);
            }
        }
    }
    public function _add($symbiont){
        if(isset($symbiont['full'])){
            if($symbiont['function']&&$symbiont['function']!="main"){
                return $symbiont['full'];
            }
            global $kernel;
            $kernel->library_add('paragraph');            
            $p=new paragraph();
            $p->add('', '', '');
            $id=$p->id;
            return $symbiont['full'].'.'.$id;
        }
        else{
            return '';
        }
    }
    public function _delete($symbiont){
        global $kernel;
        $kernel->library_add('paragraph');
        $p=new paragraph($symbiont['function']);
        $p->del();
    }
    public function _administrate($symbiont=''){
        if($symbiont['full']=='text'){
            $design=$this->_check('add');
            $d=new design($design, 'text');
        }
        else{
            $this->___admin('', $symbiont['function'], $symbiont['full']);
        }
    }
}
?>
